import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-08-23
 * Time: 17:49
 */

class IntCmp implements Comparator<Integer> {

    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);//Integer实现了Comparable接口
    }
}
public class Test {
    public int[] smallestK1(int[] arr, int k){
        int[] ret=new int[k];
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();
        for (int i = 0; i < arr.length; i++) {
            priorityQueue.offer(arr[i]);
        }
        for (int i = 0; i < k; i++) {
            ret[i]=priorityQueue.poll();
        }
        return ret;
    }

    public int[] smallestK2(int[] arr,int k){
        int[] ret=new int[k];
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>(new IntCmp());
        int i=0;
        for (i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }
        for (i=k; i < arr.length ; i++) {
            int peek=priorityQueue.peek();
            if(peek > arr[i]){
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }
        for (int j = 0; j < k; j++) {
            ret[j]=priorityQueue.poll();
        }
        return ret;
    }
    public static void main(String[] args) {
        String str1="Hello";
        String str2="World";
        String str3="haha";
//        String ret=String.join(" ",str1,str2,str3);
//        System.out.println(ret);
//        String ret=str1.concat(str2);
//        System.out.println(ret);

        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>(new IntCmp());
        priorityQueue.offer(12);
        priorityQueue.offer(23);
        priorityQueue.offer(34);
        System.out.println(priorityQueue.peek());


    }
}
